<?php
/**
 * 获取考勤记录信息的API接口
 */

session_start();
require_once '../includes/config.php';
require_once '../includes/database.php';
require_once '../includes/auth.php';
require_once '../includes/attendance_manager.php';

// 检查权限
$auth = getAuth();
$auth->requirePermission('super_admin');

// 获取记录ID
$recordId = $_GET['id'] ?? 0;

if (!$recordId) {
    http_response_code(400);
    echo json_encode(['error' => '记录ID不能为空']);
    exit;
}

try {
    // 初始化数据库和考勤管理器
    $database = getDatabaseConnection();
    $attendanceManager = new AttendanceManager($database);
    
    // 获取考勤记录信息
    $record = $attendanceManager->getAttendanceRecordById($recordId);
    
    if (!$record) {
        http_response_code(404);
        echo json_encode(['error' => '考勤记录不存在']);
        exit;
    }
    
    // 返回考勤记录信息
    header('Content-Type: application/json');
    echo json_encode($record);
    
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['error' => '服务器错误: ' . $e->getMessage()]);
}
?>
